﻿/* DotNetHoldem 
 * .Net Solution that allows to use OpenHoldem with .Net logic
 * Author: Óscar Andreu
 * oesido at gmail dot com
 * Licensed under GPLv3 - 2012
 */

using System;
using System.Collections.Generic;
using DotNetBotLogic.Classes;
using DotNetBotLogic.Controllers;
using DotNetBotLogic.Enums;
using DotNetBotLogic.Classes.Log;

namespace DotNetBotLogic
{
    public class MainController
    {
        #region static

        internal static int BetTurn = 1;

        private static double handsPlayed;
        internal static double HandsPlayed
        {
            get { return handsPlayed; }
            set
            {
                if (handsPlayed != value)
                {
                    handsPlayed++;
                    betRound = 0;

                    Logger.Log(string.Format("\n ------------- NEW HAND ({0})-----------", handsPlayed));
                }

                handsPlayed = value;
            }
        }

        private static BetRounds betRound;
        internal static BetRounds BetRound
        {
            get { return betRound; }
            set
            {
                if (betRound != value)
                    BetTurn = 1;
                else
                    BetTurn++;

                betRound = value;
            }
        }

        #endregion

        #region Variables

        private SwagController swagController = null;
        internal SwagController SwagController
        {
            get { return swagController == null ? new SwagController(this) : swagController; }
        }

        private CallController callController = null;
        internal CallController CallController
        {
            get { return callController == null ? new CallController(this) : callController; }
        }

        private AlliController alliController = null;
        internal AlliController AlliController
        {
            get { return alliController == null ? new AlliController(this) : alliController; }
        }

        #endregion

        #region Constructor

        public MainController(IntPtr getSymbolFromDll, IntPtr getPlayerName)
        {
            OhHelper.Oh = new OH_Wrapper(getSymbolFromDll, getPlayerName);

            BaseController.BBlind = OhHelper.GetSymbol(Symbols.bblind);
            Logger.Log(string.Format("Setting BBlind to {0}.", BaseController.BBlind));
        }

        #endregion

        /// <summary>
        /// Process de query message
        /// </summary>
        /// <param name="pquery"></param>
        /// <returns></returns>S
        public double ProcessQuery(string pquery)
        {
            double lResult = 0;
            // look at google for c++ struct to c#
            //double pot = oh.getsym("potcommon");
            //holdem_state state = OhHelper.GetHoldemState();
            //Console.WriteLine(state.m_title);

            if (pquery == "dll$swag")
            {
                lResult = SwagController.GetActionResult();
            }
            else if (pquery == "dll$call")
            {
                lResult = CallController.GetActionResult();
            }
            else if (pquery == "dll$alli")
            {
                HandsPlayed = OhHelper.GetSymbol(Symbols.handsplayed);
                BetRound = OhHelper.GetBetRound();

                lResult = AlliController.GetActionResult();

                lResult = 0;
            }
            else if (pquery == "dll$srai")
            {
                lResult = 0;
            }
            else if (pquery == "ddll$rais")
            {
                lResult = 0;
            }
            else if (pquery == "dll$prefold")
            {
                lResult = 0;
            }
            else if (pquery == "dll$rebuy")
            {
                lResult = 0;
            }
            else if (pquery == "dll$delay")
            {
                lResult = 0;
            }
            else if (pquery == "dll$chat")
            {
                lResult = 0;
            }
            else if (pquery == "dll$play")
            {
                lResult = 1;
            }
            
            return lResult;
        }

    }
}
